package com.xsglxt;

import java.util.ArrayList;
import java.util.Scanner;

public class Manage {
    private ArrayList<Student> students = new ArrayList<>();
    //添加学生
    public void addStudent(Student student) {
        students.add(student);
        System.out.println("添加学生成功");
    }
    //删除学生
    public boolean deleteStudent(String id) {
        return students.removeIf(student -> student.getId().equals(id));
    }
    //修改学生

    //查询学生
    public Student findStudent(Student student){
        for (Student s : students) {
            if (s.getId().equals(student.getId())) {
                return s;
            }
            if (s.getName().equals(student.getName())) {
                return s;
            }
        }
        return null;
    }
    //查询所有学生
    public ArrayList<Student> findAllStudent(){
        return students;
    }

    //通过id查询索引
    public static int getIndex(ArrayList<Student> list, String sid) {
        for (int i = 0; i < list.size(); i++) {
            if (list.get(i).getId().equals(sid)) {
                return i;
            }
        }
        return -1;
    }
    public ArrayList<Student> getStudents() {
        return students;
    }
}

